package com.maigao.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public final class SpringUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContextParam) throws BeansException {
        applicationContext = applicationContextParam;
    }

    public static Object getBean(String tClass) {
        return applicationContext.getBean(tClass);
    }
    public static <T> T getBean(Class<T> clz) throws BeansException
    {
        T result = (T) applicationContext.getBean(clz);
        return result;
    }

    public static <T> T getBean(String id, Class<T> tClass) {

        return applicationContext.getBean(id, tClass);
    }
}
